import WRequest from "./request";
import { BASE_URL } from "./request/config";
import LocalCache from "@/utils/cache";

const wRequest = new WRequest({
  baseURL: BASE_URL,
  timeout: 10000,
  interceptors: {
    requestInterceptor: (config) => {
      // const token = "";
      const token = LocalCache.getCache("token");
      if (token) {
        //axios 里面类型发生改变 所有需要判断一下才能用
        if (config && config.headers) {
          config.headers.Authorization = `Bearer ${token}`;
        }
      }
      return config;
    },
    requestInterceptorCatch: (error) => {
      return error;
    },
    responseInterceptor: (res) => {
      return res;
    },
    responseInterceptorCatch: (error) => {
      return error;
    },
  },
});
export default wRequest;
